package uk.co.q3c.deplan.server.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import uk.co.q3c.deplan.client.domain.dag.ChangeInvalidException;
import uk.co.q3c.deplan.client.domain.dag.CycleDetectedException;
import uk.co.q3c.deplan.client.domain.resource.PersistenceReferenceException;
import uk.co.q3c.deplan.client.domain.task.BaseTask;
import uk.co.q3c.deplan.client.service.ServiceFactory;
import uk.co.q3c.deplan.server.rcp.model.TaskListListener;

/**
 * Intended to be used to create a database containing known data. Not really developed yet
 * 
 * @author DSowerby 30 Jun 2008 20:51:40
 * 
 */
public class TestDatabaseCreator {
	transient protected final Logger logger = Logger.getLogger(getClass().getName());
	BaseTask root;
	long DAYINMILLISECONDS = 1000 * 60 * 60 * 24;
	int HOURINSECONDS = 60 * 60;
	private final List<TaskListListener> listeners = new ArrayList<TaskListListener>();
	ServiceFactory connection;

	private void creeteDb() throws CycleDetectedException, ChangeInvalidException, PersistenceReferenceException {
		// connection = Model.getDao();
		root = new BaseTask(connection);
		root.setName("root");

		BaseTask a = new BaseTask(connection);
		a.setName("a");
		a.setPriority(100);
		a.setParentTask(root);

		BaseTask a1 = new BaseTask(connection);
		a1.setName("a1");
		a1.setPriority(200);
		a1.setParentTask(a);

		BaseTask a1a1 = new BaseTask(connection);
		a1a1.setName("a1a1");
		a1a1.setPriority(100);
		a1a1.setParentTask(a1);

		Date sd = new Date();
		a1a1.setStartRemaining(sd);
		Date fd = new Date();
		fd.setTime(sd.getTime() + DAYINMILLISECONDS);
		a1a1.setPlannedFinish(fd);
		a1a1.setWorkRemaining(HOURINSECONDS * 10);
		a1a1.setWorkRemaining(HOURINSECONDS * 1);

		BaseTask a1a2 = new BaseTask(connection);
		a1a2.setName("a1a2");
		a1a2.setPriority(100);
		a1a2.setParentTask(a1);
		sd = new Date();
		sd.setTime(fd.getTime());
		a1a2.setStartRemaining(sd);
		fd = new Date();
		fd.setTime(sd.getTime() + (8 * DAYINMILLISECONDS));
		a1a2.setPlannedFinish(fd);
		a1a2.setWorkRemaining(HOURINSECONDS * 20);
		a1a2.setWorkRemaining(HOURINSECONDS * 2);

		BaseTask b = new BaseTask(connection);
		b.setName("b");
		b.setPriority(100);
		b.setParentTask(root);
		sd = new Date();
		sd.setTime(sd.getTime() + (4 * DAYINMILLISECONDS));
		b.setStartRemaining(sd);
		fd = new Date();
		fd.setTime(sd.getTime() + (3 * DAYINMILLISECONDS));
		b.setStartRemaining(sd);
		b.setPlannedFinish(fd);
		b.setWorkRemaining(HOURINSECONDS * 30);
		b.setWorkRemaining(HOURINSECONDS * 5);

		logger.info("Task Manager root has children: " + root.getSubTasks()
				.size());
	}

}
